package com.itcat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itcat.mysql.pojo.UmsMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.management.relation.Relation;
import java.util.List;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/4/1 23:03]
 */
@Mapper
public interface UmsMenuMapper extends BaseMapper<UmsMenu> {

    @Select("<script>" +
            "SELECT * FROM ums_menu WHERE id in " +
            "(SELECT menu_id FROM ums_role_menu_relation WHERE hidden=0  AND role_id in" +
            "<foreach item = 'item' index = 'index' collection = 'ids' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "GROUP BY menu_id" +
            ")" +
            "</script>")
    List<UmsMenu> selectMenuList(@Param("ids") List<Long> ids);

    @Delete("DELETE FROM ums_role_menu_relation WHERE menu_id=#{id}")
    void deleteMenu(Long id);
}
